matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

# 计算每列元素的最大宽度
column_widths = [max(len(str(matrix[i][j])) for i in range(len(matrix))) for j in range(len(matrix[0]))]

# 打印上边框
print('+' + '+'.join('-' * (width + 2) for width in column_widths) + '+')

for row in matrix:
    print('|', end='')
    for j in range(len(row)):
        element = str(row[j])
        print(' ' + element + ' '*(column_widths[j] - len(element) + 1), end='')
    print('|')

# 打印下边框
print('+' + '+'.join('-' * (width + 2) for width in column_widths) + '+')
